﻿package _1_LabelAndButton;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
 * 2011-5-31 20:49:32
 * @author Administrator
 * 演示JLabel及ImageIcon的使用
 */
public class TLabel_Image {
    JFrame frame;
    Container contentPane;
    JLabel label1,label2;
    public TLabel_Image(){
        frame=new JFrame("测试Label");
        contentPane=frame.getContentPane();
        contentPane.setLayout(new FlowLayout());
        label1=new JLabel(new ImageIcon("QQ.jpg"));
        label1.setPreferredSize(new Dimension(label1.getIcon().getIconWidth(),label1.getIcon().getIconHeight()));
        contentPane.add(label1);
        label2=new JLabel(new ImageIcon("QQ1.jpg"));
        label2.setPreferredSize(new Dimension(label2.getIcon().getIconWidth(),label2.getIcon().getIconHeight()));
        contentPane.add(label2);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
    public static void main(String args[]){
        new TLabel_Image();
    }
}
